package org.controller;

import com.alibaba.fastjson.JSON;
import org.entity.Books;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletResponse;
import java.awt.print.Book;
import java.io.IOException;
import java.io.PrintWriter;

@Controller
@RequestMapping(value = "ajax")
public class AjaxController {
    //ajax页面提交的处理：/ajax/test01?name=xxx
    @RequestMapping(value = "test01")
    public void test01(String name, HttpServletResponse response) throws IOException {
        System.out.println("test01点击测试");
        PrintWriter out = response.getWriter();
        if(name.equals("admin")) {
            out.println("true");
        }
        else{
            out.println("false");
        }
    }
    @RequestMapping(value = "test02")
    public void test02(HttpServletResponse response) throws IOException {
        System.out.println("test02点击测试");
        PrintWriter out = response.getWriter();
        Books books = new Books(1,"测试书籍1",20,"测试作者1");
        out.println(books);
    }
    @RequestMapping(value = "test03")
    public void test03(HttpServletResponse response) throws IOException {
        System.out.println("test03点击测试");
        PrintWriter out = response.getWriter();
        Books books = new Books(1,"测试书籍1",20,"测试作者1");
        String jsonString = JSON.toJSONString(books);
        out.println(jsonString);
    }
}
